package com.coffeeloversupportlibrary.coffeelover.domain.explor;

import android.util.Log;

import com.coffeeloversupportlibrary.coffeelover.callback.ModelCallBack;
import com.coffeeloversupportlibrary.coffeelover.domain.explor.entity.Dialog;
import com.coffeeloversupportlibrary.core.base.BaseViewModel;
import com.coffeeloversupportlibrary.core.base.livadata.SingleLiveEvent;
import com.coffeeloversupportlibrary.core.data.DataRepository;

import java.util.List;

/**
 * @author puyv
 * @createTime 2021/11/29 10:22
 * @projectName CoffeeLoverSupportLibrary
 * @className ExploreViewModel.java
 * @description TODO
 */
public class ExploreViewModel extends BaseViewModel<ExploreModel> {

    private SingleLiveEvent<String> failureToast=new SingleLiveEvent<>();
    private SingleLiveEvent<Dialog> notifyDialogUpdate=new SingleLiveEvent<>();
    private SingleLiveEvent<List<Dialog>> dialogInfo=new SingleLiveEvent<>();


    public SingleLiveEvent<String> getFailureToast() {
        return failureToast;
    }

    public SingleLiveEvent<Dialog> getNotifyDialogUpdate() {
        return notifyDialogUpdate;
    }

    public SingleLiveEvent<List<Dialog>> getDialogInfo() {
        return dialogInfo;
    }

    public void startDialog(int type){
        Log.e("PUYV","ViewModel层调用startDialog");
        mModel.openDialog(type, new ModelCallBack<Dialog, String>() {
            @Override
            public void onSuccess(Dialog dialog) {
                Log.e("PUYV","Model 层数据准备就绪，回调ViewNodel");
                //success 更新对话
                if(null!=dialog){
                    Log.e("PUYV","Viewmodel 更新数据  UI感知数据");
                    notifyDialogUpdate.setValue(dialog);
                }

            }

            @Override
            public void Failure(String s) {
                  //failure 更新   UI
                failureToast.setValue(s);
            }
        });

    }

    public void dialog(int intentAction){
        mModel.dialog(intentAction, new ModelCallBack<List<Dialog>, String>() {
            @Override
            public void onSuccess(List<Dialog> dialogs) {
                //成功 展示对话内容
                if(null!=dialogs){
                    dialogInfo.setValue(dialogs);
                }
            }

            @Override
            public void Failure(String s) {
                 //failure 通知 UI
                failureToast.setValue(s);
            }
        });

    }

    @Override
    protected void setModel() {
          mModel=new ExploreModel(DataRepository.getInstance());
    }
}
